package com.sxt.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sxt.util.RedisUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequestMapping("/redis")
@RestController
public class RedisController {
	 private static int ExpireTime = 60;   // redis中存储的过期时间60s

	    @Resource
	    private RedisUtil redisUtil;

	    /**
	     * http://localhost:8083/redis/set?key=id1&value=1ceshi测试
	     * @param key
	     * @param value
	     * @return
	     */
	    @RequestMapping("set")
	    public boolean redisset(String key, String value){
//	        UserEntity userEntity =new UserEntity();
//	        userEntity.setId(Long.valueOf(1));
//	        userEntity.setGuid(String.valueOf(1));
//	        userEntity.setName("zhangsan");
//	        userEntity.setAge(String.valueOf(20));
//	        userEntity.setCreateTime(new Date());

	        //return redisUtil.set(key,userEntity,ExpireTime);
	    	log.info("key:"+key);
	        return redisUtil.set(key,value);
	    }

	    
	    /**
	     * http://localhost:8083/redis/get?key=id1
	     * @param key
	     * @return
	     */
	    @RequestMapping("get")
	    public Object redisget(String key){
	        return redisUtil.get(key);
	    }

	    @RequestMapping("expire")
	    public boolean expire(String key){
	        return redisUtil.expire(key,ExpireTime);
	    }
	    
	    
	    
}
